<?php
	//跨域被请求必须加,冒号后面代表请求的网站网址,*代表任何网站都可以跨域请求该php页面的数据
	header("Access-Control-Allow-Origin:*");
	include('include/config.php');
	include('include/rsa.php');
	include('include/mysql.php');
	$xlxs = $_POST['data'];
	$userInfo = $_POST['userInfo'];
	
	/*
		验证账户信息
	*/
	$user = $userInfo['user'];
	$password = $userInfo['password'];
	$userdata = rsaInfo($user, $password);
	$userObj = array(
		"user" => $userdata['user'],
		"password" => $userdata['password']
	);
	$verifyCode = verifyUserInfo($userObj);
	
	/*
		mysql.php
		插入顺序
		创建表，没有自动跳过，但还是要执行创建，因为不确定表是否存在	createTable($xlxsName)
		插入字段	=> 	insertData($fieldList, $xlxsName)
		插入数据	=>	insertDatas($fieldList, $listInfo, $xlxsName)
	*/
	
	// 获取表名称
	$xlxsName = $verifyCode['data'][0]['xlsxName'];
	// 获取数据表字段并存入$fieldList
	$fieldList = array();
	$listInfo = array();
	forEach($xlxs[0] as $key => $val){
		array_push($fieldList, $key);
		array_push($listInfo, $val);
	}
	// 建表
	$create = createTable($xlxsName);
	// 插入字段
	$insert = insertData($fieldList, $xlxsName);
	forEach($xlxs as $key => $val){
		$listInfo = array();
		forEach($xlxs[$key] as $k => $v){
			array_push($listInfo, $v);
		}
		$data = insertDatas($fieldList, $listInfo, $xlxsName);
	}
	if(!empty($data)){
		echo json_encode($data);exit();
	} else {
		echo json_encode('服务器异常');exit();
	}
	
	
	
	
	









?>